<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" value="${pageContext.request.contextPath }"></c:set>
<!DOCTYPE html>
<html lang="en">
<c:import url="header.jsp"></c:import>

<body>
<body>

	<div id="wrapper">

		<!-- Navigation -->
		<c:import url="nav.jsp"></c:import>

		<div id="page-wrapper">
			<div class="container-fluid">

				<div class="row">
					<h2 class="title text-center">比赛列表</h2>

					<a class="btn btn-primary" href="match_edit.html"
						id="match-add_btn">添加比赛</a>
				</div>
				<div class="row">

					<table class="table table-bordered match-table">
						<thead>
							<tr>
								<th>比赛名字</th>
								<th>编辑时间</th>
								<th>操作</th>
								<th>報名表</th>
								<th>状态管理</th>
								<th>其他</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach var="match" items="${matchList}">
								<tr>
									<th scope="row"><a href="#">${match.match_name }</a></th>
									<td>${match.create_date }</td>
									<td><a href="match_edit.html?match_id=${match.match_id }">修改</a>
										<a href="api_deleteMatch?match_id=${match.match_id }">删除</a> <a
										href="sign_list.html?match_id=${match.match_id }">报名情况</a></td>
									<td><c:if test="${empty match.file_url}">未上传报名表 </c:if> <c:if
											test="${not empty match.file_url}"><a class="btn btn-private btn-lg"
										href="${ctx}/download?fileName=${match.file_url}">下载</a>重新</c:if>
										<button name="${match.match_id}" class="btfile">上传报名表</button>
										</td>
									<td>
										<div class="btn-group">
											<button type="button" class="btn btn-default dropdown-toggle"
												data-toggle="dropdown" aria-haspopup="true"
												aria-expanded="false">
												<c:if test="${match.state==0}">
			                                                       			 未发布
				                                                    </c:if>
												<c:if test="${match.state==1}">
				                                                      		 正在报名
				                                                    </c:if>
												<c:if test="${match.state==2}">
				                                                       		结束报名
				                                                    </c:if>
												<c:if test="${match.state==3}">
				                                                        	公布结果
				                                                    </c:if>
												<span class="caret"></span>
											</button>
											<ul class="dropdown-menu">
												<c:if test="${match.state!=0}">
													<li><a
														href="api_changeMatchState?match_id=${match.match_id}&state=0">未发布</a></li>
												</c:if>
												<c:if test="${match.state!=1}">
													<li><a
														href="api_changeMatchState?match_id=${match.match_id }&state=1">正在报名</a></li>
												</c:if>
												<c:if test="${match.state!=2}">
													<li><a
														href="api_changeMatchState?match_id=${match.match_id }&state=2">结束报名</a></li>
												</c:if>
												<c:if test="${match.state!=3}">
													<li><a
														href="api_changeMatchState?match_id=${match.match_id }&state=3">公布结果</a></li>
												</c:if>
											</ul>
										</div>
									</td>

									<td><a
										href="${ctx }/manage/award.html?match_id=${match.match_id}">录入奖项</a></td>
								</tr>
							</c:forEach>

						</tbody>
					</table>

				</div>
				<div id="form"></div>
			</div>
		</div>


		<!-- /#page-wrapper -->

	</div>



	<!-- /#wrapper -->
	<!-- jQuery -->
	<c:import url="footer.jsp"></c:import>
	<script type="text/javascript">
		$(function() {
			$(".btfile")
					.click(
							function() {
								alert($(this).attr("name"));
								var form = $('<form></form>');
								var url = "${ctx}/manage/uploadFile";
								// 设置属性  
								form.attr('enctype', "multipart/form-data");
								form.attr('method', 'post');
								form.attr('action', url)
								// form的target属性决定form在哪个页面提交  
								// 创建Input  
								var my_input = $('<input type="file" name="file"/>');
								var my_hidden = $("<input type='hidden' name='matchid'/>");
								my_hidden.attr('value', $(this).attr("name"));
								//   my_input.attr('value', my_val);  
								// 附加到Form  
								form.append(my_input);
								form.append(my_hidden);
								var my_button = $("<button class=\"btn btn-default\">上传</button>");
								form.append(my_button);
								$("#form").html("");
								$("#form").append(form);

							});
		});
	</script>
</body>
</html>